/*
 * @FilePath: /app/app.cpp
 * @Author: Wilson
 * @Descripttion: 
 * @Date: 2021-12-16 10:07:19
 * @LastEditors: Wilson
 * @LastEditTime: 2021-12-16 10:51:02
 */
#include "app.h"

#include <glog/logging.h>

#include <dwg.h>

namespace app
{
    void init()
    {
        LOG(INFO) << "app init...";

        BITCODE_BL i;
        int success;
        Dwg_Data dwg;

        memset(&dwg, 0, sizeof(Dwg_Data));
        dwg.opts = 1;
        success = dwg_read_file("test/test.dwg", &dwg);
        if (!success)
        {
            LOG(ERROR) << "read dwg error: " << success;
            return;
        }
        for (int i = 0; i < dwg.num_objects; i++)
        {
            Dwg_Entity_LINE *line;
            Dwg_Entity_CIRCLE *circle;
            Dwg_Entity_TEXT *text;
            
            switch (dwg.object[i].type)
            {
            case DWG_TYPE_LINE:
                line = dwg.object[i].tio.entity->tio.LINE;
                LOG(INFO)<<"line: start x="<<line->start.x<<", start y="<<line->start.y
                    <<"; end x="<<line->end.x<<", end y="<<line->end.y;
                break;
            case DWG_TYPE_CIRCLE:
                circle = dwg.object[i].tio.entity->tio.CIRCLE;
                LOG(INFO)<<"circle: center x="<<circle->center.x<<", y="<<circle->center.y
                    <<", radius="<<circle->radius;
                break;
            case DWG_TYPE_TEXT:
                text = dwg.object[i].tio.entity->tio.TEXT;
                LOG(INFO)<<"text: x="<<text->ins_pt.x<<", y="<<text->ins_pt.y
                    <<", text_value="<<text->text_value;
                break;
            default:
                LOG(INFO)<<"object type: "<<dwg.object[i].type;
                break;
            }
        }
        dwg_free(&dwg);
    }
}